package com.feijiang.controller;


import com.feijiang.entity.ExpeStep;
import com.feijiang.service.IExpeStepService;
import com.feijiang.util.ResponseData;
import javax.annotation.Resource;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2021-12-28
 */
@RestController
@RequestMapping("/expe-step")
public class ExpeStepController {

  @Resource
  IExpeStepService iExpeStepService;

  @PostMapping("/add")
  public ResponseData add(@RequestBody ExpeStep expeStep) {
    return ResponseData.success(iExpeStepService.add(expeStep));
  }

  @PostMapping("/edit")
  public ResponseData edit(@RequestBody ExpeStep expeStep) {
    if (expeStep.getId() == null) {
      return ResponseData.error("缺少ID");
    }
    return ResponseData.success(iExpeStepService.edit(expeStep));
  }

  @PostMapping("/delete/{id}")
  public ResponseData delete(@PathVariable("id") int id) {
    return ResponseData.success(iExpeStepService.delete(id));
  }

  @GetMapping("/list")
  public ResponseData list(@RequestParam(name = "pageSize") int pageSize,
      @RequestParam(name = "pageNum") int pageNum) {
    Assert.isTrue(pageNum > 0 && pageSize > 0, "请输入正确的参数");

    return ResponseData.success(iExpeStepService.select(pageSize, pageNum));
  }

  @GetMapping("/{id}")
  public ResponseData getById(@PathVariable("id") int id) {
    return ResponseData.success(iExpeStepService.getById(id));
  }
}
